<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Retrieves metadata for the fields of a statement prepared by 
  sqlsrv_prepare or sqlsrv_query</title>
 </head>
 <body class="docs"></div>
<div id="layout">
  <div id="layout-content"><div id="function.sqlsrv-field-metadata" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sqlsrv_field_metadata</h1>
  <p class="verinfo">(No version information available, might only be in Git)</p><p class="refpurpose"><span class="refname">sqlsrv_field_metadata</span> &mdash; <span class="dc-title">Retrieves metadata for the fields of a statement prepared by 
  <span class="function"><a href="sqlsrv_prepare.html" class="function">sqlsrv_prepare()</a></span> or <span class="function"><a href="sqlsrv_query.html" class="function">sqlsrv_query()</a></span>
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.sqlsrv-field-metadata-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sqlsrv_field_metadata</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$stmt</code></span>
   ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   Retrieves metadata for the fields of a statement prepared by 
   <span class="function"><a href="sqlsrv_prepare.html" class="function">sqlsrv_prepare()</a></span> or <span class="function"><a href="sqlsrv_query.html" class="function">sqlsrv_query()</a></span>. 
   <span class="function"><strong>sqlsrv_field_metadata()</strong></span> can be called on a statement before 
   or after statement execution.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-function.sqlsrv-field-metadata-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">stmt</code></dt>

     <dd>

      <p class="para">
       The statment resource for which metadata is returned.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.sqlsrv-field-metadata-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns an array of arrays on success. Otherwise, <strong><code>FALSE</code></strong> is returned. 
   Each returned array is described by the following table:
   <table class="doctable table">
   <caption><strong>Array returned by sqlsrv_field_metadata</strong></caption>
   
    <thead>
     <tr>
      <th>Key</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>Name</td>
      <td>The name of the field.</td>
     </tr>

     <tr>
      <td>Type</td>
      <td>The numeric value for the SQL type.</td>
     </tr>

     <tr>
      <td>Size</td>
      <td>The number of characters for fields of character type, the number of 
      bytes for fields of binary type, or <strong><code>NULL</code></strong> for other types.</td>
     </tr>

     <tr>
      <td>Precision</td>
      <td>The precision for types of variable precision, <strong><code>NULL</code></strong> for other types.</td>
     </tr>

     <tr>
      <td>Scale</td>
      <td>The scale for types of variable scale, <strong><code>NULL</code></strong> for other types.</td>
     </tr>

     <tr>
      <td>Nullable</td>
      <td>An enumeration indicating whether the column is nullable, not nullable, 
      or if it is not known.</td>
     </tr>

    </tbody>
   
  </table>

  For more information, see <a href="http://msdn.microsoft.com/en-us/library/cc296197.aspx" class="link external">&raquo;&nbsp;sqlsrv_field_metadata</a> 
  in the Microsoft SQLSRV documentation.
  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.sqlsrv-field-metadata-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2580">
    <p><strong>Example #1 <span class="function"><strong>sqlsrv_field_metadata()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$serverName&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"serverName\sqlexpress"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$connectionInfo&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">"Database"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"AdventureWorks"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UID"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"username"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"PWD"</span><span style="color: #007700">=&gt;</span><span style="color: #DD0000">"password"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_connect</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$serverName</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$connectionInfo</span><span style="color: #007700">);<br />if(&nbsp;</span><span style="color: #0000BB">$conn&nbsp;</span><span style="color: #007700">===&nbsp;</span><span style="color: #0000BB">false&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;die(&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">sqlsrv_errors</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"SELECT&nbsp;*&nbsp;FROM&nbsp;Table_1"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">sqlsrv_prepare</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$sql&nbsp;</span><span style="color: #007700">);<br /><br />foreach(&nbsp;</span><span style="color: #0000BB">sqlsrv_field_metadata</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$stmt&nbsp;</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$fieldMetadata&nbsp;</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach(&nbsp;</span><span style="color: #0000BB">$fieldMetadata&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$name&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"</span><span style="color: #0000BB">$name</span><span style="color: #DD0000">:&nbsp;</span><span style="color: #0000BB">$value</span><span style="color: #DD0000">&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"&lt;br&nbsp;/&gt;"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-function.sqlsrv-field-metadata-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="sqlsrv_client_info.html" class="function" rel="rdfs-seeAlso">sqlsrv_client_info()</a> - Returns information about the client and specified connection</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>